<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'>
    <title>FLUX Studio</title>
</head>

<body>
    <!-- <script src='js/lib/svgeditor/jquery.js'></script> -->
    <!--<script src='js/lib/jquery-1.11.0.min.js'></script>-->
    <script src='js/lib/three/three.min.js'></script>

    <div class='wrapper'>
        <section class='top-menu'></section>
        <section class='tour-overlay'></section>
        <section class='content'>
            <div class='spinner-roller absolute-center'></div>
        </section>
        <section class='notification'></section>
        <section id='announcement'></section>
    </div>
</body>
<script>
    function launch() {
        var script = document.createElement('script'),
            cssLink = document.createElement('link'),
            head = document.querySelector('head'),
            body = document.querySelector('body'),
            dev = localStorage['dev'] === 'true',
            getStarted = function(ghostPort) {
                script.setAttribute('src', 'js/require.js');
                script.dataset.main = 'js/main.js?v=' + (dev ? '' : window.FLUX.timestamp);
                body.appendChild(script);
            },
            timer;

        // set global definition
        window.FLUX = {
            debug: location.search.indexOf('debug') !== -1 || dev,
            version: window["electron"] ? electron.version : "web-dev",
            timestamp: (new Date()).getTime(),
            onLine: navigator.onLine,
            os: ('undefined' === typeof nw ? undefined : os),
            ghostPort: 8000,
            allowTracking: false, //localStorage['allow-tracking'] === 'true',
            dev: dev
        };

        if(window["electron"]) {
            let ipc = electron.ipc,
                events = electron.events;

            ipc.on(events.BACKEND_UP, (sender, status) => {
                window.FLUX.ghostPort = status.port;
                window.FLUX.logfile = status.logfile;
                getStarted(status.port);
                console.log(`Backend start at ${status.port}`);
            });

            ipc.on(events.BACKEND_DOWN, () => {});

            ipc.on(events.NOTIFY_BACKEND_STATUS, (sender, status) => {
                if(status.backend.alive) {
                    window.FLUX.ghostPort = status.backend.port;
                    window.FLUX.logfile = status.backend.logfile;
                    getStarted(status.backend.port);
                    console.log(`Backend ready at ${status.backend.port}`);
                }
            });

            ipc.send(events.CHECK_BACKEND_STATUS);
            ipc.send(events.NOTIFY_LANGUAGE, localStorage.getItem('active-lang'));

        } else {
            window.process = {}
            getStarted();
        }

        cssLink.setAttribute('rel', 'stylesheet');
        cssLink.setAttribute('href', 'css/main.css?v=' + window.FLUX.timestamp);
        head.appendChild(cssLink);
        head.appendChild(cssLink);

        if(localStorage.getItem('poke-ip-addr') == 'undefined') {
            localStorage.setItem('poke-ip-addr', '192.168.1.1')
        }
    }
    launch();
</script>

</html>
